package com.example.room.dao;

import androidx.lifecycle.LiveData;
import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.Query;
import androidx.room.Update;

import com.example.room.entity.Student;

import java.util.List;

@Dao
public interface StudentDao {

    //增加操作
    @Insert
    public void insetStudent(Student... students);

    //删除操作
    @Delete
    public void deleteStudent(Student... students);

    //删除所有
    @Query("DELETE FROM student")
    public void deleteAllStudent();

    //修改
    @Update
    public void updateStudent(Student... students);

    //查询所有
    @Query("SELECT * FROM student")
    public List<Student> queryAll();

    //可以配合LiveData实现自动查询
    @Query("SELECT * FROM student")
    public LiveData<List<Student>> getAll();

    //按照id查找
    @Query("SELECT * FROM student WHERE id = :id")
    public List<Student> queryById(int id);
}
